package com.seal.commons.utils.mask;

import org.apache.commons.lang3.StringUtils;

/**
 * ClassName:MaskOffCodeUtils <br/>
 * Function: 统一掩码处理 <br/>
 * Date:     2019-07-03 09:54 <br/>
 *
 * @author yong.huang
 * @see
 * @since JDK 1.8
 */
public final class MaskOffCodeUtils {


    /**
     * 对用户姓名进行隐码处理
     * @param name
     * @return
     */
    public static String maskOffName( final String name ){
        String userName = name;
        if (StringUtils.isNotBlank( name )){
            if (name.length() > 2) {
                userName = name.substring(0, 1) + "*" + name.substring(name.length() - 1);
            } else if (name.length() == 2) {
                userName = name.substring(0, 1) + "*";
            }
        }
        return userName;
    }


    /**
     * 对银行卡号进行隐码处理
     * @param bank_card_number
     * @return
     */
    public static String maskOffBankCardNumber( final String bank_card_number ){
        String bankCardNumber = bank_card_number;
        if (StringUtils.isNotBlank(bank_card_number)){
            if ( bankCardNumber.length() >= 7 ) {
                bankCardNumber = bank_card_number.substring(0, 3) + "***" + bank_card_number.substring(bank_card_number.length() - 4);
            }
        }
        return bankCardNumber;
    }


    /**
     * 对手机号码进行隐码处理
     * @param phone_number
     * @return
     */
    public static String maskOffPhoneNumber( final String phone_number ){
        String phoneNumber = phone_number;
        if (StringUtils.isNotBlank( phone_number )) {
            if ( phoneNumber.length() >= 7 ) {
                phoneNumber = phone_number.substring(0, 3) + "***" + phone_number.substring(phone_number.length() - 4);
            }
        }
        return phoneNumber;
    }


    /**
     * 对身份证号码进行隐码处理
     * @param id_card_num
     * @return
     */
    public static String maskOffIdCardNum( final String id_card_num ){
        String idCardNum = id_card_num;
        if (StringUtils.isNotBlank( id_card_num )) {
            if ( id_card_num.length() >= 7 ) {
                idCardNum = id_card_num.substring(0, 4) + "***" + id_card_num.substring(id_card_num.length() - 3);
            }
        }
        return idCardNum;
    }

    /**
     * 对统一社会信用代码进行隐码处理
     * @param social_credit_code
     * @return
     */
    public static String maskOffSocialCreditCode(final String social_credit_code){
        String socialCreditCode = social_credit_code;
        if (StringUtils.isNotBlank( social_credit_code )){
            if(social_credit_code.length() >= 8){
                socialCreditCode = social_credit_code.substring(0,social_credit_code.length()-4) + "****";
            }
        }
        return socialCreditCode;
    }

}
